package solution;

import java.util.ArrayList;
import java.util.List;

class Solution {
    public void rotate(int[] nums, int k) {
        int len = nums.length;

        k = k % len;

        if (len == 1 || k == 0) {
            return;
        }

        k = k % len;

        int index = len - k;
        int cur = index;

        List<Integer> list = new ArrayList<>();
        do {
            list.add(nums[cur]);
            cur = (cur + 1) % len;
        } while (cur != index);

        for (int i = 0; i < len; i++) {
            nums[i] = list.get(i);
        }
    }
}